﻿using HirelSeriesH.Entity;
using HirelSeriesH.Tools;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;

namespace HirelSeriesH
{
    public partial class CorrectForm : Form
    {
        List<NumericUpDown> channel01 = new List<NumericUpDown>();
        List<NumericUpDown> channel02 = new List<NumericUpDown>();
        List<NumericUpDown> channel03 = new List<NumericUpDown>();
        List<NumericUpDown> channel04 = new List<NumericUpDown>();
        List<NumericUpDown> channel05 = new List<NumericUpDown>();
        List<NumericUpDown> channel06 = new List<NumericUpDown>();
        List<NumericUpDown> channel07 = new List<NumericUpDown>();
        List<NumericUpDown> channel08 = new List<NumericUpDown>();
        /*List<NumericUpDown> channel09 = new List<NumericUpDown>();
        List<NumericUpDown> channel10 = new List<NumericUpDown>();
        List<NumericUpDown> channel11 = new List<NumericUpDown>();
        List<NumericUpDown> channel12 = new List<NumericUpDown>();
        List<NumericUpDown> channel13 = new List<NumericUpDown>();
        List<NumericUpDown> channel14 = new List<NumericUpDown>();
        List<NumericUpDown> channel15 = new List<NumericUpDown>();
        List<NumericUpDown> channel16 = new List<NumericUpDown>();*/

        List<List<NumericUpDown>> channel = new List<List<NumericUpDown>>();

        public CorrectForm()
        {
            InitializeComponent();
            channel01.Add(NudBHDZ01);
            channel01.Add(NudCYDZ01);
            channel01.Add(NumGWJZ_K01);
            channel01.Add(NumGWJZ_B01);
            channel01.Add(NudGWJZ1_K01);
            channel01.Add(NudGWJZ1_B01);
            channel01.Add(NudGWJZ10_K01);
            channel01.Add(NudGWJZ10_B01);
            channel01.Add(NudGWJZ100_K01);
            channel01.Add(NudGWJZ100_B01);
            channel01.Add(NudGWJZ1000_K01);
            channel01.Add(NudGWJZ1000_B01);
            channel01.Add(NudDLYZ01);
            channel01.Add(NudBeInit01);

            channel02.Add(NudBHDZ02);
            channel02.Add(NudCYDZ02);
            channel02.Add(NumGWJZ_K02);
            channel02.Add(NumGWJZ_B02);
            channel02.Add(NudGWJZ1_K02);
            channel02.Add(NudGWJZ1_B02);
            channel02.Add(NudGWJZ10_K02);
            channel02.Add(NudGWJZ10_B02);
            channel02.Add(NudGWJZ100_K02);
            channel02.Add(NudGWJZ100_B02);
            channel02.Add(NudGWJZ1000_K02);
            channel02.Add(NudGWJZ1000_B02);
            channel02.Add(NudDLYZ02);
            channel02.Add(NudBeInit02);

            channel03.Add(NudBHDZ03);
            channel03.Add(NudCYDZ03);
            channel03.Add(NumGWJZ_K03);
            channel03.Add(NumGWJZ_B03);
            channel03.Add(NudGWJZ1_K03);
            channel03.Add(NudGWJZ1_B03);
            channel03.Add(NudGWJZ10_K03);
            channel03.Add(NudGWJZ10_B03);
            channel03.Add(NudGWJZ100_K03);
            channel03.Add(NudGWJZ100_B03);
            channel03.Add(NudGWJZ1000_K03);
            channel03.Add(NudGWJZ1000_B03);
            channel03.Add(NudDLYZ03);
            channel03.Add(NudBeInit03);

            channel04.Add(NudBHDZ04);
            channel04.Add(NudCYDZ04);
            channel04.Add(NumGWJZ_K04);
            channel04.Add(NumGWJZ_B04);
            channel04.Add(NudGWJZ1_K04);
            channel04.Add(NudGWJZ1_B04);
            channel04.Add(NudGWJZ10_K04);
            channel04.Add(NudGWJZ10_B04);
            channel04.Add(NudGWJZ100_K04);
            channel04.Add(NudGWJZ100_B04);
            channel04.Add(NudGWJZ1000_K04);
            channel04.Add(NudGWJZ1000_B04);
            channel04.Add(NudDLYZ04);
            channel04.Add(NudBeInit04);

            channel05.Add(NudBHDZ05);
            channel05.Add(NudCYDZ05);
            channel05.Add(NumGWJZ_K05);
            channel05.Add(NumGWJZ_B05);
            channel05.Add(NudGWJZ1_K05);
            channel05.Add(NudGWJZ1_B05);
            channel05.Add(NudGWJZ10_K05);
            channel05.Add(NudGWJZ10_B05);
            channel05.Add(NudGWJZ100_K05);
            channel05.Add(NudGWJZ100_B05);
            channel05.Add(NudGWJZ1000_K05);
            channel05.Add(NudGWJZ1000_B05);
            channel05.Add(NudDLYZ05);
            channel05.Add(NudBeInit05);

            channel06.Add(NudBHDZ06);
            channel06.Add(NudCYDZ06);
            channel06.Add(NumGWJZ_K06);
            channel06.Add(NumGWJZ_B06);
            channel06.Add(NudGWJZ1_K06);
            channel06.Add(NudGWJZ1_B06);
            channel06.Add(NudGWJZ10_K06);
            channel06.Add(NudGWJZ10_B06);
            channel06.Add(NudGWJZ100_K06);
            channel06.Add(NudGWJZ100_B06);
            channel06.Add(NudGWJZ1000_K06);
            channel06.Add(NudGWJZ1000_B06);
            channel06.Add(NudDLYZ06);
            channel06.Add(NudBeInit06);

            channel07.Add(NudBHDZ07);
            channel07.Add(NudCYDZ07);
            channel07.Add(NumGWJZ_K07);
            channel07.Add(NumGWJZ_B07);
            channel07.Add(NudGWJZ1_K07);
            channel07.Add(NudGWJZ1_B07);
            channel07.Add(NudGWJZ10_K07);
            channel07.Add(NudGWJZ10_B07);
            channel07.Add(NudGWJZ100_K07);
            channel07.Add(NudGWJZ100_B07);
            channel07.Add(NudGWJZ1000_K07);
            channel07.Add(NudGWJZ1000_B07);
            channel07.Add(NudDLYZ07);
            channel07.Add(NudBeInit07);

            channel08.Add(NudBHDZ08);
            channel08.Add(NudCYDZ08);
            channel08.Add(NumGWJZ_K08);
            channel08.Add(NumGWJZ_B08);
            channel08.Add(NudGWJZ1_K08);
            channel08.Add(NudGWJZ1_B08);
            channel08.Add(NudGWJZ10_K08);
            channel08.Add(NudGWJZ10_B08);
            channel08.Add(NudGWJZ100_K08);
            channel08.Add(NudGWJZ100_B08);
            channel08.Add(NudGWJZ1000_K08);
            channel08.Add(NudGWJZ1000_B08);
            channel08.Add(NudDLYZ08);
            channel08.Add(NudBeInit08);

            /*channel09.Add(NudBHDZ09);
            channel09.Add(NudCYDZ09);
            channel09.Add(NumGWJZ_K09);
            channel09.Add(NumGWJZ_B09);
            channel09.Add(NudGWJZ1_K09);
            channel09.Add(NudGWJZ1_B09);
            channel09.Add(NudGWJZ10_K09);
            channel09.Add(NudGWJZ10_B09);
            channel09.Add(NudGWJZ100_K09);
            channel09.Add(NudGWJZ100_B09);
            channel09.Add(NudGWJZ1000_K09);
            channel09.Add(NudGWJZ1000_B09);
            channel09.Add(NudDLYZ09);
            channel09.Add(NudBeInit09);

            channel10.Add(NudBHDZ10);
            channel10.Add(NudCYDZ10);
            channel10.Add(NumGWJZ_K10);
            channel10.Add(NumGWJZ_B10);
            channel10.Add(NudGWJZ1_K10);
            channel10.Add(NudGWJZ1_B10);
            channel10.Add(NudGWJZ10_K10);
            channel10.Add(NudGWJZ10_B10);
            channel10.Add(NudGWJZ100_K10);
            channel10.Add(NudGWJZ100_B10);
            channel10.Add(NudGWJZ1000_K10);
            channel10.Add(NudGWJZ1000_B10);
            channel10.Add(NudDLYZ10);
            channel10.Add(NudBeInit10);

            channel11.Add(NudBHDZ11);
            channel11.Add(NudCYDZ11);
            channel11.Add(NumGWJZ_K11);
            channel11.Add(NumGWJZ_B11);
            channel11.Add(NudGWJZ1_K11);
            channel11.Add(NudGWJZ1_B11);
            channel11.Add(NudGWJZ10_K11);
            channel11.Add(NudGWJZ10_B11);
            channel11.Add(NudGWJZ100_K11);
            channel11.Add(NudGWJZ100_B11);
            channel11.Add(NudGWJZ1000_K11);
            channel11.Add(NudGWJZ1000_B11);
            channel11.Add(NudDLYZ11);
            channel11.Add(NudBeInit11);

            channel12.Add(NudBHDZ12);
            channel12.Add(NudCYDZ12);
            channel12.Add(NumGWJZ_K12);
            channel12.Add(NumGWJZ_B12);
            channel12.Add(NudGWJZ1_K12);
            channel12.Add(NudGWJZ1_B12);
            channel12.Add(NudGWJZ10_K12);
            channel12.Add(NudGWJZ10_B12);
            channel12.Add(NudGWJZ100_K12);
            channel12.Add(NudGWJZ100_B12);
            channel12.Add(NudGWJZ1000_K12);
            channel12.Add(NudGWJZ1000_B12);
            channel12.Add(NudDLYZ12);
            channel12.Add(NudBeInit12);

            channel13.Add(NudBHDZ13);
            channel13.Add(NudCYDZ13);
            channel13.Add(NumGWJZ_K13);
            channel13.Add(NumGWJZ_B13);
            channel13.Add(NudGWJZ1_K13);
            channel13.Add(NudGWJZ1_B13);
            channel13.Add(NudGWJZ10_K13);
            channel13.Add(NudGWJZ10_B13);
            channel13.Add(NudGWJZ100_K13);
            channel13.Add(NudGWJZ100_B13);
            channel13.Add(NudGWJZ1000_K13);
            channel13.Add(NudGWJZ1000_B13);
            channel13.Add(NudDLYZ13);
            channel13.Add(NudBeInit13);

            channel14.Add(NudBHDZ14);
            channel14.Add(NudCYDZ14);
            channel14.Add(NumGWJZ_K14);
            channel14.Add(NumGWJZ_B14);
            channel14.Add(NudGWJZ1_K14);
            channel14.Add(NudGWJZ1_B14);
            channel14.Add(NudGWJZ10_K14);
            channel14.Add(NudGWJZ10_B14);
            channel14.Add(NudGWJZ100_K14);
            channel14.Add(NudGWJZ100_B14);
            channel14.Add(NudGWJZ1000_K14);
            channel14.Add(NudGWJZ1000_B14);
            channel14.Add(NudDLYZ14);
            channel14.Add(NudBeInit14);

            channel15.Add(NudBHDZ15);
            channel15.Add(NudCYDZ15);
            channel15.Add(NumGWJZ_K15);
            channel15.Add(NumGWJZ_B15);
            channel15.Add(NudGWJZ1_K15);
            channel15.Add(NudGWJZ1_B15);
            channel15.Add(NudGWJZ10_K15);
            channel15.Add(NudGWJZ10_B15);
            channel15.Add(NudGWJZ100_K15);
            channel15.Add(NudGWJZ100_B15);
            channel15.Add(NudGWJZ1000_K15);
            channel15.Add(NudGWJZ1000_B15);
            channel15.Add(NudDLYZ15);
            channel15.Add(NudBeInit15);

            channel16.Add(NudBHDZ16);
            channel16.Add(NudCYDZ16);
            channel16.Add(NumGWJZ_K16);
            channel16.Add(NumGWJZ_B16);
            channel16.Add(NudGWJZ1_K16);
            channel16.Add(NudGWJZ1_B16);
            channel16.Add(NudGWJZ10_K16);
            channel16.Add(NudGWJZ10_B16);
            channel16.Add(NudGWJZ100_K16);
            channel16.Add(NudGWJZ100_B16);
            channel16.Add(NudGWJZ1000_K16);
            channel16.Add(NudGWJZ1000_B16);
            channel16.Add(NudDLYZ16);
            channel16.Add(NudBeInit16);*/

            channel.Add(channel01);
            channel.Add(channel02);
            channel.Add(channel03);
            channel.Add(channel04);
            channel.Add(channel05);
            channel.Add(channel06);
            channel.Add(channel07);
            channel.Add(channel08);
            /*channel.Add(channel09);
            channel.Add(channel10);
            channel.Add(channel11);
            channel.Add(channel12);
            channel.Add(channel13);
            channel.Add(channel14);
            channel.Add(channel15);
            channel.Add(channel16);*/
        }
        private void CorrectForm_Load(object sender, EventArgs e)
        {

            for (int i = 0; i < Global.Global.ChannelList.Count; i++)
            {
                Channel channel = Global.Global.ChannelList[i];
                List<NumericUpDown> numericUps = this.channel[i];

                numericUps[0].Value = channel.BHDZ;
                numericUps[1].Value = channel.CYDZ;
                numericUps[2].Value = channel.GWJZ_K;
                numericUps[3].Value = channel.GWJZ_B;
                numericUps[4].Value = channel.GWJZ1_K;
                numericUps[5].Value = channel.GWJZ1_B;
                numericUps[6].Value = channel.GWJZ10_K;
                numericUps[7].Value = channel.GWJZ10_B;
                numericUps[8].Value = channel.GWJZ100_K;
                numericUps[9].Value = channel.GWJZ100_B;
                numericUps[10].Value = channel.GWJZ1000_K;
                numericUps[11].Value = channel.GWJZ1000_B;
                numericUps[12].Value = channel.DLYZ;
                numericUps[13].Value = channel.ToInit;
            }

        }
        private void BtnSave_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Global.Global.ChannelList.Count; i++)
            {
                List<NumericUpDown> numericUps = this.channel[i];

                Global.Global.ChannelList[i].BHDZ = numericUps[0].Value;
                Global.Global.ChannelList[i].CYDZ = numericUps[1].Value;
                Global.Global.ChannelList[i].GWJZ_K = numericUps[2].Value;
                Global.Global.ChannelList[i].GWJZ_B = numericUps[3].Value;
                Global.Global.ChannelList[i].GWJZ1_K = numericUps[4].Value;
                Global.Global.ChannelList[i].GWJZ1_B = numericUps[5].Value;
                Global.Global.ChannelList[i].GWJZ10_K = numericUps[6].Value;
                Global.Global.ChannelList[i].GWJZ10_B = numericUps[7].Value;
                Global.Global.ChannelList[i].GWJZ100_K = numericUps[8].Value;
                Global.Global.ChannelList[i].GWJZ100_B = numericUps[9].Value;
                Global.Global.ChannelList[i].GWJZ1000_K = numericUps[10].Value;
                Global.Global.ChannelList[i].GWJZ1000_B = numericUps[11].Value;
                Global.Global.ChannelList[i].DLYZ = numericUps[12].Value;
                Global.Global.ChannelList[i].ToInit = numericUps[13].Value;

                //更新数据库 
                MySqlParameter[] para = new MySqlParameter[] {
                    new MySqlParameter("@ID", Global.Global.ChannelList[i].ID),
                    new MySqlParameter("@BHDZ", Global.Global.ChannelList[i].BHDZ),
                    new MySqlParameter("@CYDZ", Global.Global.ChannelList[i].CYDZ),
                    new MySqlParameter("@GWJZ_K", Global.Global.ChannelList[i].GWJZ_K),
                    new MySqlParameter("@GWJZ_B", Global.Global.ChannelList[i].GWJZ_B),
                    new MySqlParameter("@GWJZ1_K", Global.Global.ChannelList[i].GWJZ1_K),
                    new MySqlParameter("@GWJZ1_B", Global.Global.ChannelList[i].GWJZ1_B),
                    new MySqlParameter("@GWJZ10_K", Global.Global.ChannelList[i].GWJZ10_K),
                    new MySqlParameter("@GWJZ10_B", Global.Global.ChannelList[i].GWJZ10_B),
                    new MySqlParameter("@GWJZ100_K", Global.Global.ChannelList[i].GWJZ100_K),
                    new MySqlParameter("@GWJZ100_B", Global.Global.ChannelList[i].GWJZ100_B),
                    new MySqlParameter("@GWJZ1000_K", Global.Global.ChannelList[i].GWJZ1000_K),
                    new MySqlParameter("@GWJZ1000_B", Global.Global.ChannelList[i].GWJZ1000_B),
                    new MySqlParameter("@DLYZ", Global.Global.ChannelList[i].DLYZ),
                    new MySqlParameter("@ToInit", Global.Global.ChannelList[i].ToInit)};

                DBHelper.ExecuteNonQuery(DBSql.UPDATE_HTRB_CHANNEL_CORRECT, 1, para);
            }

            MessageBox.Show("校准参数设置成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

        private void BtnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void BtnNH_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Global.Global.ChannelList.Count; i++)
            {
                Channel channel = Global.Global.ChannelList[i];
                //查询老化板工位记录
                MySqlParameter[] paras = new MySqlParameter[] { new MySqlParameter("@ChID", channel.ID) };
                DataSet dataSetPos = DBHelper.GetDataSet(DBSql.SELECT_HTRB_CHANNEL_POSITIONS, 1, paras);

                for (int j = 0; j < dataSetPos.Tables[0].Rows.Count; j++)
                {
                    for (int n = 0; n < channel.Positions.Count; n++)
                    {
                        Position position = channel.Positions[n];
                        if (position.Index == int.Parse(dataSetPos.Tables[0].Rows[j]["PosIndex"].ToString()))
                        {
                            /*position.ID = dataSetPos.Tables[0].Rows[j]["ID"].ToString();
                            position.ChID = dataSetPos.Tables[0].Rows[j]["ChID"].ToString();
                            position.ChannelName = dataSetPos.Tables[0].Rows[j]["ChannelName"].ToString();
                            position.Index = int.Parse(dataSetPos.Tables[0].Rows[j]["PosIndex"].ToString());
                            position.BasicValue = decimal.Parse(dataSetPos.Tables[0].Rows[j]["BasicValue"].ToString());*/

                            //参数校正项
                            position.GWJZ_K = decimal.Parse(dataSetPos.Tables[0].Rows[j]["GWJZ_K"].ToString());
                            position.GWJZ_B = decimal.Parse(dataSetPos.Tables[0].Rows[j]["GWJZ_B"].ToString());
                            position.GWJZ1_K = decimal.Parse(dataSetPos.Tables[0].Rows[j]["GWJZ1_K"].ToString());
                            position.GWJZ1_B = decimal.Parse(dataSetPos.Tables[0].Rows[j]["GWJZ1_B"].ToString());
                            position.GWJZ10_K = decimal.Parse(dataSetPos.Tables[0].Rows[j]["GWJZ10_K"].ToString());
                            position.GWJZ10_B = decimal.Parse(dataSetPos.Tables[0].Rows[j]["GWJZ10_B"].ToString());
                            position.GWJZ100_K = decimal.Parse(dataSetPos.Tables[0].Rows[j]["GWJZ100_K"].ToString());
                            position.GWJZ100_B = decimal.Parse(dataSetPos.Tables[0].Rows[j]["GWJZ100_B"].ToString());
                            position.GWJZ1000_K = decimal.Parse(dataSetPos.Tables[0].Rows[j]["GWJZ1000_K"].ToString());
                            position.GWJZ1000_B = decimal.Parse(dataSetPos.Tables[0].Rows[j]["GWJZ1000_B"].ToString());

                            break;
                        }
                    }
                }

            }
            MessageBox.Show("更新成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
